<template>
  <div class="divBox" style="padding:10px 0">
    <el-card class="box-card" shadow="never">
      <div slot="header" class="clearfix" style="margin-top:10px">
      </div>
      <el-table
        v-loading="listLoading"
        :data="list"
        size="mini"
        style="width: 100%"
      >
        <el-table-column
          align="center"
          label="ID"
          min-width="50"
          prop="fileId"
        />
        <el-table-column
          align="center"
          label="播放地址"
          min-width="50"
          prop="mediaUrl"
        >
        </el-table-column>
        <el-table-column
          align="center"
          label="时长（秒）"
          min-width="50"
          prop="duration"
        />
        <el-table-column align="center" label="操作" min-width="50">
          <template slot-scope="scope">
            <div style="display: inline-block">
              <el-button size="mini" type="text" @click="openInvitee(scope.row)">播放</el-button>
              <el-button size="mini" type="text" @click="deleteInvitee(scope.row)">删除</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-dialog
      :visible.sync="modals"
      class="paymentFooter"
      footerHide
      scrollable
      style="height: 800px"
      title="直播回放"
      width="900"
      @on-cancel="cancel"
    >
      <div class="video-box">
        <video width="100%" height="100%" :src="currentVideoUrl" controls></video>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { livePlaybackList, liveplaybackdel } from '@/api/marketing.js'
import GoodList from '@/components/goodList'

export default {
  name: 'invite',
  components: { GoodList },
  props: {
    liveId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      listLoading: false,
      list: [],
      modals: false,
      Loading: false,
      currentVideoUrl: ''
    }
  },
  watch: {
    liveId(val) {
      if (val) {
        this.getlist()
      }
    }
  },
  created() {
    this.getlist()
  },
  methods: {
    cancel() {
      this.modals = false
    },
    openInvitee(row) {
      this.currentVideoUrl = row.mediaUrl
      this.modals = true
    },
    deleteInvitee() {
      this.$confirm('此操作将永久删除回放视频, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        liveplaybackdel(row.fileId).then(parmas => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.getlist()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    getlist() {
      this.listLoading = true
      let parmas = {
        liveId: this.liveId
      }
      livePlaybackList(parmas).then((res) => {
        this.listLoading = false
        this.list = res.results
      }).catch((res) => {
        this.listLoading = false
      })
    },
  }
}
</script>

<style lang="scss" scoped>
.divBox {
  .el-switch__label--right {
    position: absolute;
    right: 10px;
  }

  .el-switch__label--left {
    position: absolute;
    left: 10px;
  }

  .video-box {
    width: 500px;
    height: 500px;
    margin: 0 auto;

    video {
      margin: 0 auto;
    }
  }
}
</style>
